package com.xjrsoft.module.workflow.controller;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xjrsoft.common.flowableUtils.MyProcessDiagramGenerator;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.secure.XjrUser;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.core.tool.utils.*;
import com.xjrsoft.module.base.entity.XjrBaseTempfield;
import com.xjrsoft.module.base.service.IXjrBaseTempfieldService;
import com.xjrsoft.module.base.service.IXjrBaseUserService;
import com.xjrsoft.module.language.entity.XjrLgMark;
import com.xjrsoft.module.language.service.IXjrLgMarkService;
import com.xjrsoft.module.workflow.dto.GetPageHistoryDto;
import com.xjrsoft.module.workflow.dto.GetPageListNwfTaskDto;
import com.xjrsoft.module.workflow.dto.NwfSchemeInfoDto;
import com.xjrsoft.module.workflow.entity.XjrNwfScheme;
import com.xjrsoft.module.workflow.entity.XjrNwfSchemeauth;
import com.xjrsoft.module.workflow.entity.XjrNwfSchemeinfo;
import com.xjrsoft.module.workflow.mapper.NwfTaskMapper;
import com.xjrsoft.module.workflow.service.IXjrNwfSchemeAuthService;
import com.xjrsoft.module.workflow.service.IXjrNwfSchemeInfoService;
import com.xjrsoft.module.workflow.service.IXjrNwfSchemeService;
import com.xjrsoft.module.workflow.service.IXjrNwfTaskService;
import com.xjrsoft.module.workflow.vo.NwfSchemeInfoVo;
import com.xjrsoft.module.workflow.vo.NwfSchemeVo;
import com.xjrsoft.module.workflow.vo.NwfSchemeauthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.engine.*;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.InputStream;
import java.util.*;

@Slf4j
@ControllerAdvice
@RestController
@RequestMapping("/workflow-scheme-info")
@Api(value = "工作流控制器", tags = "工作流控制器")
@Configuration
public class NwfSchemeInfoController {


    @Autowired
    private IXjrBaseUserService xjrBaseUserService;

    @Autowired
    private TaskService taskService;

    @Autowired
    private HistoryService historyService;

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private IXjrBaseTempfieldService xjrBaseTempfieldService;

    @Autowired
    private NwfTaskMapper nwfTaskMapper;

    @Autowired
    private IXjrNwfSchemeInfoService nwfschemeinfoService;

    @Autowired
    private IXjrNwfSchemeService nwfSchemeService;

    @Autowired
    private IXjrNwfSchemeAuthService nwfSchemeAuthService;

    @Autowired
    private IXjrBaseTempfieldService tempfieldService;

    @Autowired
    private IXjrNwfTaskService nwfTaskService;

    @Autowired
    private IXjrLgMarkService lgMarkService;

    @Autowired
    private ProcessEngineConfiguration processEngineConfiguration;


    /**
     * @return
     * @author 湘北智造-框架开发组
     * @date:2019年12月25日
     * @url: /newModel
     * @description:新建模型,返回modelId
     */
    @PostMapping("/new-model")
    @ApiOperation(value = "新建模型")
    public Response newModel() {
        return Response.ok(FlowableUtil.newModel(), "创建模型成功!");
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/10/20
     * @Param:[]
     * @return:void
     * @Description:获取编辑模板
     */
    @SneakyThrows
    @GetMapping("/get-model")
    @ApiOperation(value = "获取编辑模板")
    @ApiImplicitParam(name = "modelId", dataType = "string", paramType = "query", value = "模型id")
    public void getEditorJson(String modelId) {
        String editorJson = "";
        XjrNwfSchemeinfo xjrNwfSchemeinfo = nwfschemeinfoService.getByModelId(modelId);
        NwfSchemeInfoVo nwfSchemeInfoVo = BeanUtil.copy(xjrNwfSchemeinfo, NwfSchemeInfoVo.class);
        // 新增的时候返回的数据 字符串
        editorJson = FlowableUtil.getEditorJson(modelId).toString();
        if (nwfSchemeInfoVo != null) {
            String fId = nwfSchemeInfoVo.getId();
            // 部署ID
            String deployId = nwfSchemeInfoVo.getDeploymentId();
            // 修改
            XjrBaseTempfield xjrTempKeyvalue = tempfieldService.getByIdAndType(fId + "_" + deployId, "3");
            if (xjrTempKeyvalue != null) {
                JSONObject parse = (JSONObject) JSONObject.parse(editorJson);
                String colValueStr = xjrTempKeyvalue.getFvalue();
                JSONObject colValue = (JSONObject) JSONObject.parse(colValueStr);
                parse.put("model", colValue);
                editorJson = parse.toJSONString();
            }
        }
        Response.ok(editorJson.toString(), "操作成功!");
    }


    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/10/20
     * @Param:[]
     * @return:void
     * @Description:根据modelId使json转Xml
     */
    @GetMapping("/json-to-xml/{deploymentId}")
    @ApiOperation(value = "json转Xml")
    @ApiImplicitParam(name = "deploymentId", dataType = "string", paramType = "query", value = "流程部署id")
    public Response json2Xml(@PathVariable String deploymentId) {
        JSONObject json = new JSONObject();
        json.put("xmlContent", FlowableUtil.json2Xml(deploymentId));
        return Response.ok(json, "操作成功!");
    }


    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/24
     * @Param:[dto]
     * @return:com.xjrsoft.common.result.Response
     * @Description:流程模板分页查询
     */
    @GetMapping("/page")
    @ApiOperation(value = "流程模板信息分页查询")
    public Response selectDataPage(GetPageListNwfTaskDto dto) {
        return Response.ok(nwfschemeinfoService.selectDataPage(dto));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/20
     * @Param:[dto]
     * @return:com.xjrsoft.common.result.Response
     * @Description:流程模板查询
     */
    @GetMapping()
    @ApiOperation(value = "流程模板查询")
    public Response selectData(GetPageListNwfTaskDto dto) {
        return Response.ok(nwfschemeinfoService.selectDataPage(dto));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/10/21
     * @Param:[modelId:模板ID]
     * @return:void
     * @Description:根据model获取工作流设计模板信息
     */
    @SneakyThrows
    @GetMapping("/info/{id}")
    @ApiOperation(value = "根据model获取工作流设计模板信息")
    @ApiImplicitParam(name = "id", dataType = "string", value = "模型id")
    public Response toUpdatePage(@PathVariable String id) {
        JSONObject json = new JSONObject();
        XjrNwfSchemeinfo xjrNwfSchemeinfo = nwfschemeinfoService.getByModelId(id);
        if (xjrNwfSchemeinfo != null) {
            NwfSchemeInfoVo nwfSchemeInfoVo = BeanUtil.copy(xjrNwfSchemeinfo, NwfSchemeInfoVo.class);
            XjrNwfScheme xjrNwfScheme = nwfSchemeService.getBySchemeInfoId(xjrNwfSchemeinfo.getId());
            String fjsonStr = xjrNwfScheme.getFjson();
            // 返回翻译标记名称
            JSONObject fJson = JSONObject.parseObject(fjsonStr);
            JSONObject menu = fJson.getJSONObject("properties").getJSONObject("menu");
            if (menu != null) {
                XjrLgMark lgMark = lgMarkService.getLgMarkByCode(menu.getString("F_LgMarkCode"));
                if (lgMark != null) {
                    menu.put("F_LgMarkName", lgMark.getName());
                }
            }
            json.put("json", fJson.toJSONString());
            json.put("xml", xjrNwfScheme.getContent());
            if (nwfSchemeInfoVo != null) {
                String fId = nwfSchemeInfoVo.getId();
                json.put("schemeinfo", nwfSchemeInfoVo);
                // 查询表xjr_nwf_schemeauth数据
                List<XjrNwfSchemeauth> list = nwfSchemeAuthService.getBySchemeInfoId(fId);
                json.put("schemeAuthList", BeanUtil.copyList(list, NwfSchemeauthVo.class));
                // 查询表xjr_Nwf_Scheme数据,返回bpmn文件
                XjrNwfScheme nwfScheme = nwfSchemeService.getBySchemeInfoId(fId);
                json.put("scheme", BeanUtil.copy(nwfScheme, NwfSchemeVo.class));
                return Response.ok(json);
            }
        }
        return Response.notOk();
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/20
     * @Param:[parameterMap]
     * @return:com.xjrsoft.common.result.Response
     * @Description:保存流程设计模板信息接口
     */
    @SneakyThrows
    @PostMapping()
    @ApiOperation(value = "保存流程设计模板信息接口")
    public Response save(@RequestBody NwfSchemeInfoDto dto) throws Exception {
        return Response.ok(nwfschemeinfoService.saveProcess(dto, SecureUtil.getUser()));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/20
     * @Param:[params]
     * @return:void
     * @Description:更新模板信息接口
     */
    @SneakyThrows
    @PutMapping("/{id}")
    @ApiOperation(value = "更新模板信息接口")
    @ApiImplicitParam(name = "id", dataType = "string", value = "流程模板id")
    public Response update(@PathVariable String id, @RequestBody NwfSchemeInfoDto dto) throws Exception {
        // 获取当前登录用户
        XjrUser currentUser = SecureUtil.getUser();
        if (currentUser != null) {
            return Response.status(nwfschemeinfoService.updateProcess(dto, currentUser));
        }
        return Response.notOk("当前用户未登录!");
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/10/21
     * @Param:[fId:主键ID]
     * @return:void
     * @Description:根据主键删除流程信息模板
     */
    @SneakyThrows
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据主键删除流程信息模板")
    @ApiImplicitParam(name = "id", dataType = "string", value = "流程模板id")
    public Response delete(@PathVariable("id") String id) {
        nwfschemeinfoService.deleteProcess(id);
        return Response.ok();
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/10/23
     * @Param:[nwfSchemeInfoId：]
     * @return:com.xjrsoft.common.result.Response
     * @Description:读取流程图资源
     */
    @SneakyThrows
    @GetMapping("/read-resource")
    @ApiOperation(value = "读取流程图资源")
    @ApiImplicitParam(name = "F_Id", dataType = "string", value = "流程模板id")
    public void readResource(@RequestParam("F_Id") String id) {
        HttpServletResponse response = WebUtil.getResponse();
        String imgPath = IoUtil.getProjectPath() + "static" + StringPool.SLASH + "images" + StringPool.SLASH + "flowableFile";
        File file = null;
        // 根据流程信息主键获取deploymentId
        XjrNwfSchemeinfo xjrNwfSchemeinfo = nwfschemeinfoService.getById(id);
        if (xjrNwfSchemeinfo != null) {
            id = xjrNwfSchemeinfo.getDeploymentId();
        }
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(id).singleResult();
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
        MyProcessDiagramGenerator pec = new MyProcessDiagramGenerator(1.0);
        InputStream imageStream = pec.generateDiagram(bpmnModel, "png", "宋体", "微软雅黑", "黑体", processEngineConfiguration.getClassLoader(), 1.0, true);
        String filePath = IoUtil.saveBit(imageStream, imgPath);
//        String filePath = FlowableUtil.readResource(id);
        file = new File(filePath);
        if (!file.exists()) {
            String projectPath = IoUtil.getProjectPath();
            file = FileUtil.file(projectPath + filePath);
        }

        if (file == null) {
            try {
                ObjectMapper objectMapper = new ObjectMapper();
                String result = objectMapper.writeValueAsString(Response.notOk("文件不存在！"));
                response.getOutputStream().write(result.getBytes());
                return;
            } catch (JsonProcessingException e) {
                log.error(e.getMessage(), e);
            }
        } else {
            // 设置下载文件名
            response.setHeader("Content-Disposition", "inline;fileName=\"" + new String((file.getName()).getBytes("utf-8"), "ISO8859-1") + "\"");
            FileUtil.writeToStream(file, response.getOutputStream());
        }
    }

    /**
     * @Author:湘北智造-框架开发组·
     * @Date:2020/11/17
     * @Param:[id]
     * @return:com.xjrsoft.common.result.Response<java.lang.String>
     * @Description:启动流程设计状态接口 1-有效状态 0-无效状态
     */
    @PutMapping("/{id}/start")
    @ApiOperation(value = "启动流程设计状态接口")
    @ApiImplicitParam(name = "id", dataType = "string", value = "流程模板id")
    public Response<String> activateProcess(@PathVariable String id) {
        return Response.status(nwfschemeinfoService.updateProcessStatus(id, "1"));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/17
     * @Param:[id]
     * @return:com.xjrsoft.common.result.Response<java.lang.String>
     * @Description:暂停流程设计状态接口 1-有效状态 0-无效状态
     */
    @PutMapping("/{id}/stop")
    @ApiOperation(value = "停用流程设计状态接口")
    @ApiImplicitParam(name = "id", dataType = "string", value = "流程模板id")
    public Response<String> stopProcess(@PathVariable String id) {
        return Response.status(nwfschemeinfoService.updateProcessStatus(id, "0"));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/10/26
     * @Param:[nwfSchemeInfoId]
     * @return:void
     * @Description:导出通用流程接口:导出bpmn文件内容
     */
    @SneakyThrows
    @GetMapping("/process-xml")
    @ApiOperation(value = "导出通用流程接口:导出xml文件内容")
    @ApiImplicitParam(name = "id", dataType = "string", value = "流程模板id")
    public void exportGeneralProcess(@RequestParam("id") String id) {
        HttpServletResponse response = WebUtil.getResponse();
        File file = nwfschemeinfoService.exportGeneralProcess(id, 1);
        // 设置下载文件名
        response.setHeader("Content-Disposition", "inline;fileName=\"" + new String((file.getName()).getBytes("utf-8"), "ISO8859-1") + "\"");
        FileUtil.writeToStream(file, response.getOutputStream());
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/10/26
     * @Param:[nwfSchemeInfoId]
     * @return:void
     * @Description:导出流程接口:导出json文件内容
     */
    @SneakyThrows
    @GetMapping("/process-json")
    @ApiOperation(value = "导出流程接口:导出json文件内容")
    @ApiImplicitParam(name = "id", dataType = "string", value = "流程模板id")
    public void exportProcess(@RequestParam("id") String id) {
        HttpServletResponse response = WebUtil.getResponse();
        File file = nwfschemeinfoService.exportGeneralProcess(id, 0);
        // 设置下载文件名
        response.setHeader("Content-Disposition", "inline;fileName=\"" + new String((file.getName()).getBytes("utf-8"), "ISO8859-1") + "\"");
        FileUtil.writeToStream(file, response.getOutputStream());
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2021/3/4
     * @Param:[processFile]
     * @return:com.xjrsoft.common.result.Response
     * @Description:导入通用流程(导入bpmn文件,并部署)
     */
    @SneakyThrows
    @PostMapping("/import-xml")
    @ApiOperation(value = "导入通用流程:导入bpmn文件内容")
    public Response importProcess(@RequestBody MultipartFile file) {
        JSONArray retAry = new JSONArray();
        retAry.add(nwfschemeinfoService.importProcess(file));
        return Response.ok(retAry);
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2021/3/8
     * @Param:[file]
     * @return:com.xjrsoft.common.result.Response
     * @Description:导入流程(json格式)
     */
    @SneakyThrows
    @PostMapping("/import-json")
    @ApiOperation(value = "导入流程(json格式)")
    public Response importProcessByJson(@RequestBody MultipartFile file) {
        String content = nwfschemeinfoService.importProcess(file);
        return Response.ok(Arrays.asList(content.split("@XJR@")));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/10/27
     * @Param:[]
     * @return:void
     * @Description:获取流程部署的版本记录
     */
    @GetMapping("/hisitory")
    @ApiOperation(value = "获取流程部署的版本记录")
    @SneakyThrows
    public Response getHisVersion(GetPageHistoryDto dto) {
        return Response.ok(FlowableUtil.getHisVersion(dto));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/10/27o
     * @Param:[fDeploymentId:部署ID]
     * @return:void
     * @Description:更新流程部署的版本记录
     */
    @PostMapping("/change-processversion")
    @ApiOperation(value = "更新流程部署的版本记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fDeploymentId", dataType = "string", paramType = "query", value = "流程部署id"),
            @ApiImplicitParam(name = "fId", dataType = "string", paramType = "query", value = "流程模板id")
    })
    public Response updateHisVersion(String fDeploymentId, String fId) {
        XjrNwfSchemeinfo xjrNwfSchemeinfo = nwfschemeinfoService.getById(fId);
        if (xjrNwfSchemeinfo != null) {
            xjrNwfSchemeinfo.setDeploymentId(fDeploymentId);
            return Response.status(nwfschemeinfoService.updateById(xjrNwfSchemeinfo));
        } else {
            return Response.notOk();
        }
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/10/27
     * @Param:[fDeploymentId]
     * @return:void
     * @Description:版本预览
     */
    @SneakyThrows
    @GetMapping("/review-his-version")
    @ApiOperation(value = "版本预览")
    @ApiImplicitParam(name = "fDeploymentId", dataType = "string", paramType = "query", value = "流程部署id")
    public Response versionReview(@RequestParam String fDeploymentId) {
        return Response.ok(FlowableUtil.readResource(fDeploymentId));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/9
     * @Param:[processInstanceId]
     * @return:com.xjrsoft.common.result.Response
     * @Description:获取按钮信息
     */
    @GetMapping("/node-info")
    @ApiOperation(value = "获取按钮信息")
    @ApiImplicitParam(name = "processInstanceId", dataType = "string", paramType = "query", value = "流程实例id")
    public Response getNodeInfo(String processInstanceId) {
        JSONObject resultMap = new JSONObject();
        JSONObject btnObj = new JSONObject(new LinkedHashMap());
        JSONObject functionBtnObj = new JSONObject(new LinkedHashMap());
        // 获取节点的按钮信息
        String btnInfo = FlowableUtil.getNodeInfo(processInstanceId, null, "2");
        String functionButton = FlowableUtil.getNodeInfo(processInstanceId, null, "24");
        if (StringUtils.isNotBlank(functionButton)) {
            JSONArray btnList = JSONObject.parseArray(functionButton);
            for (int i = 0; i < btnList.size(); i++) {
                JSONObject btnMap = btnList.getJSONObject(i);
                String key = btnMap.getString("key");
                String val = btnMap.getString("val");
                XjrLgMark lgMarkByCode = lgMarkService.getLgMarkByCode(key);
                String btnValue = lgMarkByCode != null ? lgMarkByCode.getName() : key;
                functionBtnObj.put(val, btnValue);
            }
        }
        // 获取当前节点id
        String currentResourceId = "";
        List<Task> list = taskService.createTaskQuery().processInstanceId(processInstanceId).list();
        if (!io.jsonwebtoken.lang.Collections.isEmpty(list)) {
            if(CollectionUtil.isNotEmpty(list)) {
                currentResourceId = list.get(0).getTaskDefinitionKey();
            }
        } else {
            List<HistoricTaskInstance> hisList = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstanceId).list();
            if(CollectionUtil.isNotEmpty(hisList)) {
                currentResourceId = hisList.get(0).getTaskDefinitionKey();
            }
        }
        JSONArray historyTaskList = new JSONArray();
        if (StringUtils.isNotBlank(btnInfo)) {
            // 解析节点信息
            JSONArray btnList = JSONObject.parseArray(btnInfo);
            for (int i = 0; i < btnList.size(); i++) {
                JSONObject btnMap = btnList.getJSONObject(i);
                String key = btnMap.getString("key");
                String val = btnMap.getString("val");
                XjrLgMark lgMarkByCode = lgMarkService.getLgMarkByCode(key);
               String btnValue = lgMarkByCode != null ? lgMarkByCode.getName() : key;
                btnObj.put(val, btnValue);
                if (StringUtils.equalsIgnoreCase(val, "reject_")) {
//                    historyTaskList = nwfTaskService.historyTaskList(processInstanceId);
                    Integer act = btnMap.getInteger("act");
                    Set<HashMap<String, Object>> usetTaskNodes = new TreeSet<HashMap<String, Object>>();
                    if (act == 3) {
                        //驳回到上一个用户任务节点
                        usetTaskNodes = FlowableUtil.getUsetTaskNode(currentResourceId, processInstanceId, 2);
                        for (HashMap<String, Object> usetTaskNode : usetTaskNodes) {
                            String activityType = usetTaskNode.get("activityType").toString();
                            if (StringUtil.equals(activityType, "userTask")) {
                                historyTaskList.add(usetTaskNode);
                            }
                        }
                    } else {
                        // 所有节点（去除当前节点和重复节点)
                        usetTaskNodes = FlowableUtil.getAllNode(currentResourceId, processInstanceId, 2, new TreeSet<>());
                        for (HashMap<String, Object> usetTaskNode : usetTaskNodes) {
                            String activityType = usetTaskNode.get("activityType").toString();
                            if (StringUtil.equals(activityType, "userTask")) {
                                historyTaskList.add(usetTaskNode);
                            }
                        }
                    }
                }
            }
        }
        resultMap.put("functionBtnInfo", functionBtnObj);
        resultMap.put("btnInfo", btnObj);
        resultMap.put("retNodeList", historyTaskList);
        resultMap.put("approvalcomponents", JSON.parseObject(FlowableUtil.getNodeInfo(processInstanceId, null, "5")));
        return Response.ok(resultMap);
    }



//    /**
//     * @Author:湘北智造-框架开发组
//     * @Date:2020/11/10
//     * @Param:[]
//     * @return:void
//     * @Description:
//     */
//    @SneakyThrows
//    @GetMapping("/manual-info")
//    @ApiOperation(value = "manual-info")
//    public Response getRelationTaskList(String processInstanceId,String deploymentId) {
//        String nwfSchemeInfoId = "";
//        String version = FlowableUtil.getVersionByDepId(deploymentId);
//        List<Task> taskList = taskService.createTaskQuery().processInstanceId(processInstanceId).list();
//        ProcessInstance processInstance =runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
//        if (processInstance != null) {
//            String processDefinitionId = processInstance.getProcessDefinitionId();
//            ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
//            if (processDefinition != null) {
//                nwfSchemeInfoId = processDefinition.getDescription();
//            }
//        }
//        ArrayList<NwfSchemeauthVo> nwfSchemeauthVos = new ArrayList<>();
//        if (CollectionUtil.isNotEmpty(taskList)) {
//            Task task = taskList.get(0);
//            // 获取当前任务的节点
//            String resourceId = task.getTaskDefinitionKey();
//            String key = nwfSchemeInfoId + "_" + resourceId + "_" + version;
//            XjrBaseTempfield xjrTempKeyvalue = xjrBaseTempfieldService.getByIdAndType(key, "7");
//            if (xjrTempKeyvalue != null) {
//                String colValue = xjrTempKeyvalue.getFvalue();
//                JSONArray objects = JSONArray.parseArray(colValue);
//                    for (Object object : objects) {
//                        Map map = JSONObject.parseObject(JSONObject.toJSONString(object), Map.class);
//                        NwfSchemeauthVo nwfSchemeauthVo = new NwfSchemeauthVo();
//                        nwfSchemeauthVo.setId(map.get("F_Id").toString());
//                        nwfSchemeauthVo.setObjId(map.get("F_ObjId").toString());
//                        nwfSchemeauthVo.setObjName(map.get("F_ObjName").toString());
//                        nwfSchemeauthVo.setObjType(Integer.valueOf(map.get("F_ObjType").toString()));
//                        nwfSchemeauthVos.add(nwfSchemeauthVo);
//                    }
//                }
//        }
//            return Response.ok(nwfSchemeauthVos);
//    }
    }
